unit ballUnit;

interface

uses ExtCtrls, common, Graphics;

const R = 5;

type
  Ball = class
    dir : integer;
    x, y, x0, y0, xf, yf : double;
    vx, vy : double;
    constructor Create(_x, _y, _dir, _xl, _yl : integer);
    procedure Draw(im : TImage);
    procedure move;
  end;

implementation

{ Ball }

constructor Ball.Create;
var v : double;
begin
  x0 := _x;
  y0 := _y;
  xf := _xl;
  yf := _yl;
  dir := _dir;

  x := x0;
  y := y0;

  v := sqrt(sqr(x0-xf)+sqr(y0-yf))/((DISTANCE/STRENGTH)*DELAY_FACTOR);
  vx := v*(xf-x0)/sqrt(sqr(x0-xf)+sqr(y0-yf));
  vy := v*(yf-y0)/sqrt(sqr(x0-xf)+sqr(y0-yf));
end;

procedure Ball.Draw(im: TImage);
begin
  im.Canvas.Brush.Color := clWhite;
  im.Canvas.Ellipse(round(x-R), round(y-R), round(x+R), round(y+R));
//  im.Canvas.MoveTo(round(x0), round(y0));
//  im.Canvas.LineTo(round(xf), round(yf));
end;

procedure Ball.move;
begin
  x := x + vx;
  y := y + vy;
end;

end.
